#ifndef HTTPSERVERHANDLER_H
#define HTTPSERVERHANDLER_H

#include <../httpserver/httprequesthandler.h>
#include <../httpserver/httprequest.h>
#include <../httpserver/httpresponse.h>
#include "attendservice.h"
#include "employeeservice.h"
#include "attendancerulesservice.h"
#include "facefeaturetool.h"
#include "attendancechecker.h"
#include "userservice.h"

#include "FaceEngine.h" //seetaface的头文件
#include "opencv.hpp"   //opencv的头文件
using namespace seeta;  // seetaface里面的命名空间
using namespace cv;     // opencv里面的命名空间

namespace stefanfrings
{

class HttpServerHandler : public HttpRequestHandler
{
    Q_OBJECT
public:
    HttpServerHandler(QObject *parent = nullptr);
    void service(HttpRequest &request, HttpResponse &response) override;

private:
    AttendService* attendService;       // 考勤服务
    EmployeeService* employeeService;   // 员工服务
    AttendanceRulesService *attendanceRulesService;   // 通勤规则服务
    FaceFeatureTool * faceFeatureTool;  // 人脸识别工具
    AttendanceChecker *attendanceChecker;  //打卡工具
    UserService* userService;
    // 处理不同路径的请求
    void handleGetAttendList(HttpRequest &request, HttpResponse &response);
    void handleAddAttendRecord(HttpRequest &request, HttpResponse &response);
    void handleRegisterEmployee(HttpRequest &request, HttpResponse &response);
    void handleGetAttendanceRulesByName(HttpRequest &request, HttpResponse &response);
    void handleUpdateAttendanceRulesByName(HttpRequest &request, HttpResponse &response);
    void handleGetEmployeesByName(HttpRequest &request, HttpResponse &response);
    void handleGetAttendRecordsByEmployeeId(HttpRequest &request, HttpResponse &response);
    void handleLeaveRequest(HttpRequest &request, HttpResponse &response);
    void handleLeaveByTimeRange(HttpRequest &request, HttpResponse &response);
    void handleLogin(HttpRequest &request, HttpResponse &response);

    QAtomicInt m_totalRequests;      // 总请求数
    QAtomicInt m_activeConnections;  // 活跃连接数
    void handleServerStatus(HttpResponse& response);
    QMutex m_statusMutex;
};

} // namespace

#endif // HTTPSERVERHANDLER_H
